package edu.mju.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import edu.mju.commonutils.ReturnCode;
import edu.mju.eduservice.entity.StudyCourse;
import edu.mju.eduservice.entity.StudyTeacher;
import edu.mju.eduservice.service.StudyCourseService;
import edu.mju.eduservice.service.StudyTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 前台教师Controller
 * @Author: wyp
 * @Date: 2020/9/29 8:35
 */
@RestController
@RequestMapping("/eduservice/front/teacherFront")
public class TeacherFrontController {
    @Autowired
    private StudyTeacherService studyTeacherService;

    @Autowired
    private StudyCourseService studyCourseService;

    /**
     * 分页查询教师方法
     * @param current 当前页
     * @param size 页面大小
     * @return json
     */
    @PostMapping("/getTeacherList/{current}/{size}")
    public ReturnCode getTeacherList(@PathVariable int current,@PathVariable int size){
        Page<StudyTeacher> studyTeacherPage = new Page<>(current,size);
        Map<String,Object> map  = studyTeacherService.getTeacherList(studyTeacherPage);
        return ReturnCode.success().data(map);
    }


    @GetMapping("/getTeacherFrontInfo/{id}")
    public ReturnCode getTeacherFrontInfo(@PathVariable String id){
        //查询教师信息
        StudyTeacher studyTeacher = studyTeacherService.getById(id);

        //根据教师id查询所讲课程
        QueryWrapper<StudyCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",id);
        List<StudyCourse> courseList = studyCourseService.list(wrapper);

        Map<String,Object> map = new HashMap<>();
        map.put("teacher",studyTeacher);
        map.put("courseList",courseList);
        return ReturnCode.success().data(map);
    }

}

